local moyao = fk.CreateSkill {
  name = "emo__moyao",
  tags = {Skill.Switch},
}

moyao:addEffect("viewas", {
  anim_type = "switch",
  switch_skill_name = "emo__moyao",
  pattern = "analeptic,peach",
  prompt = function (self, player, selected_cards, selected)
    return "#emo__moyao-prompt_"..player:getSwitchSkillState(moyao.name, false, true)
  end,
  card_filter = function (self, player, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).suit == 
    (player:getSwitchSkillState(moyao.name) == fk.SwitchYin and Card.Heart or Card.Spade)
  end,
  view_as = function (self, player, cards)
    if #cards ~= 1 then return nil end
    local c
    if Fk:getCardById(cards[1]).suit == Card.Heart and player:getSwitchSkillState(moyao.name) == fk.SwitchYin then
      c = Fk:cloneCard("peach")
    elseif Fk:getCardById(cards[1]).suit == Card.Spade and player:getSwitchSkillState(moyao.name) == fk.SwitchYang then
      c = Fk:cloneCard("analeptic")
    else
      return nil
    end
    c.skillName = moyao.name
    c:addSubcard(cards[1])
    return c
  end,
  enabled_at_response = function (self, player, response)
    if not response then
      local pat = player:getSwitchSkillState(moyao.name) == fk.SwitchYang and "analeptic" or "peach"
      return Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):matchExp(pat)
    end
  end,
  before_use = function (self, player, use)
    use.extra_data = use.extra_data or {}
    use.extra_data.emo__moyao_name = use.card.trueName
  end,
  after_use = function (self, player, use)
    if player.dead then return end
    local room = player.room
    local name = (use.extra_data or Util.DummyTable).emo__moyao_name
    if not name then return end
    local cards = room:getCardsFromPileByRule(name == "analeptic" and "slash" or "jink")
    if #cards > 0 then
      room:obtainCard(player, cards, true, fk.ReasonJustMove, player, moyao.name, "@@emo__moyao-inhand")
    end
  end,
})


Fk:loadTranslationTable{
  ["emo__moyao"] = "魔药",
  [":emo__moyao"] = "转换技：阳：你可以将一张♠牌当【酒】使用，结算后摸一张【杀】；阴：你可以将一张<font color='red'>♥</font>牌当【桃】使用，结算后摸一张【闪】。",

  [":emo__moyao_yang"] = "转换技：<font color=\"#E0DB2F\">阳：你可以将一张♠牌当【酒】使用，结算后摸一张【杀】；</font>阴：你可以将一张<font color='red'>♥</font>牌当【桃】使用，结算后摸一张【闪】。",
  [":emo__moyao_yin"] = "转换技：阳：你可以将一张♠牌当【酒】使用，结算后摸一张【杀】；<font color=\"#E0DB2F\">阴：你可以将一张♥牌当【桃】使用，结算后摸一张【闪】。</font>",

  ["@@emo__moyao-inhand"] = "魔药",
  ["#emo__moyao-prompt_yang"] = "魔药:你可以将一张♠牌当【酒】使用，并摸一张【杀】",
  ["#emo__moyao-prompt_yin"] = "魔药:你可以将一张<font color='red'>♥</font>牌当【桃】使用，并摸一张【闪】",
}


return moyao
